package cn.itsource.util;

public class JSONResult<T> {
    //响应成功或者失败
    private Boolean success;
    //状态码
    private Integer code;

    private String message;

    private T data;

    public JSONResult() {
    }
    public JSONResult(Boolean success, Integer code, String message, T data) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static JSONResult ok(){
        return new JSONResult(true, 200, "操作成功", null);
    }
    public static JSONResult ok(String message){
        return new JSONResult(true, 200, message, null);
    }

    public static <V> JSONResult ok(V v){
        return new JSONResult(true, 200, "操作成功", v);
    }

    public static <V> JSONResult ok(String message,V v){
        return new JSONResult(true, 200, message, v);
    }

    public static JSONResult fail(){
        return new JSONResult(false, 500, "系统繁忙,请稍后再试!", null);
    }

    public static JSONResult fail(Integer code){
        return new JSONResult(false, code, "系统繁忙,请稍后再试!", null);
    }

    public static JSONResult fail(String message){
        return new JSONResult(false, 500, message, null);
    }


    public static JSONResult fail(Integer code,String message){
        return new JSONResult(false, code, message, null);
    }

    public static <V> JSONResult fail(V v){
        return new JSONResult(false, 500,"系统繁忙,请稍后再试!", v);
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
